<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户中心</title>
    <link rel="stylesheet" type="text/css" href="../../static/news/css/reset.css">
    <link rel="stylesheet" type="text/css" href="../../static/news/css/main.css">
    <script type="text/javascript" src="../../static/news/js/jquery-1.12.4.min.js"></script>
</head>
<body class="inframe_body">
<form class="pic_info" enctype="multipart/form-data" method="post">
    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
    <h3>头像设置</h3>
    <div class="form-group">
        <label class="label01">当前图像：</label>
        <img src="{{ users.photo }}" alt="用户图片" class="now_user_pic">

    </div>
    <div class="form-group">
        <label>修改图像：</label>
        <input type="file" name="photo" class="input_file">
    </div>
    <div class="form-group">
        <input type="button" value="保 存" class="input_sub">
    </div>
</form>
<script src="/static/news/js/jquery-1.12.4.min.js"></script>

<script>

    $(".input_sub").click(function () {

        formdata = new FormData($(".pic_info")[0]);
        console.log(formdata);

        $.ajax({
            url: "/user/photo",
            method: "post",
            data: formdata,
            processData: false,// 不处理数据
            contentType: false,//不设置类型 用FormData中的类型
            success: function (data) {
                alert("提交成功");
                console.log(data);
                {#//刷新这个页面#}
                history.go(0);
                $(".now_user_pic").attr("src", data['src'])
            },
            error: function (error) {
                alert("提交失败");
                console.log(error)
            }
        })


    })

</script>

</body>
</html>